<blockquote class="layui-elem-quote">{$title}</blockquote>
<from class="layui-form">
    <div class="layui-inline" style="width:400px;">
        <input type="text" class="layui-input" name="keyword" autocomplete="off" placeholder="请输入案例进行搜索">
    </div>
    <button class="layui-btn" type="button" lay-submit lay-filter="menu_search" id="reloadBtn"><i class="layui-icon">&#xe615;</i> 搜索</button>
    <button class="layui-btn" type="button" id="add_case"  ><i class="layui-icon">&#xe654;</i> 导入设计案例</button>
</from>
<table class="layui-hide" id="LAY_table_menu" lay-filter="menu"></table>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">添加案例</button>
    </div>
</script>
<script type="text/html" id="is_topTpl">
    <input type="checkbox" name="is_top" value="{{d.case_id}}" lay-skin="switch" lay-text="是|否" lay-filter="is_top" {{ d.is_top == 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="is_displayTpl">
    <input type="checkbox" name="is_display" value="{{d.case_id}}" lay-skin="switch" lay-text="是|否" lay-filter="is_top" {{ d.is_display == 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon">&#xe642;</i>编辑&ensp;</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon">&#xe640;</i>删除&ensp;</a>
</script>
<script>
    layui.use(['table'], function(){
        var layui_table_scrollTop = 0;
        var table = layui.table,form = layui.form;
        form.render();
        //监听工具条
        table.on('tool(menu)', function(obj){
            layui_table_scrollTop = $(".layui-table-body.layui-table-main").scrollTop();
            var data = obj.data;
            if(obj.event === 'edit'){
                layui_open("{:url('Cases/caseAdd')}",{case_id:data.case_id},data.title + " - 编辑案例","60%","80%",table,"",true);
            }else if(obj.event === 'del'){
                layer.confirm('确定要删除 《'+data.title+'》 案例？', {
                    skin: 'layui-layer-lan',
                    title:'删除',
                    btn: ['确定','取消'] //按钮
                }, function(){
                    post_sub("{:url('Cases/caseDel')}",{case_id:data.case_id},table);
                });
            }
        });
        //方法级渲染
        table.render({
            elem: '#LAY_table_menu'
            ,url: '{:url("Cases/caseList",["table"=>1])}'
            ,cellMinWidth: 80
            ,height: 'full-265'
            ,cols: [[
                {checkbox: true}
                ,{field:'case_id',title: 'ID',align:'center', width:80}
                ,{field:'title',title: '案例标题',align:'center'}
                ,{field:'classification_name',title: '分类',align:'center',sort:true}
                ,{field:'update_time',title: '更新时间',align:'center'}
                ,{field:'is_top',title: '置顶',align:'center',templet: '#is_topTpl', width:120}
                ,{field:'is_display',title: '显示',align:'center',templet: '#is_displayTpl', width:120,hide:true}
                ,{field:'reading_number_display_value',title: '阅读量',align:'center'}
                {empty name="SUBSTATIONS"},{field:'substation_name',title: '分站',align:'left'}{/empty}
                ,{title:'操作', toolbar: '#barDemo',align:'center'}
            ]]
            ,id: 'testReload'
            ,autoSort:false
            ,page: true
            ,toolbar:"#toolbarDemo"
            ,defaultToolbar:{$defaultToolbar}
            ,limit:"{$limit}"
            ,limits:[{$limits}]
            ,done:function () {
                $(".layui-table-body.layui-table-main").scrollTop(layui_table_scrollTop);
                layui_table_scrollTop = 0;
            }
        });
        //头部工具条监听事件
        table.on('toolbar(menu)', function(obj){
            layui_table_scrollTop = $(".layui-table-body.layui-table-main").scrollTop();
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'add':
                    layui_open("{:url('Cases/caseAdd')}",{},"添加案例","60%","80%",table,"",true);
                    break;
            };
        });

        //监听排序事件
        table.on('sort(menu)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            table.reload('testReload', {
                initSort: obj
                ,where: {
                    orderField: obj.field //排序字段
                    ,orderType: obj.type //排序方式
                },
                page: {
                    curr: 1
                }
            });
        });

        //搜索重载表格
        form.on('submit(menu_search)', function(data){
            table.reload('testReload', {
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });

        $(".layui-form").keydown(function(event){
            var keycode = (event.keyCode ? event.keyCode : event.which);
            if(keycode == '13'){
                //回车触发
                $('#reloadBtn').trigger('click');
            }
        });

        //导入设计案例
        $("#add_case").click(function () {
            layui_open("{:url('Cases/addDesignCase')}",{},"导入设计案例","60%","80%",table);
        });

    });
</script>
</body>
</html>